<%--
 *  File:    DTPeriodManager.jsp
 *  @Author: scottzhu 
 *  Date:    2008/9/6
 *
 *  Copyright (C) 2000 - 2001 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java"%>
<%@ page import="java.util.*"%>
<%@ page import="org.apache.log4j.Category"%>

<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/oval-tag.tld" prefix="oval"%>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom"%>

<iframe name="reloadHandler" style="display:none"></iframe>
<%
	//init param
	String strTableName = "ovorg";
  	String privilegeCode = "E0132";
	Category cat = Category.getInstance("jsp.OrgSummary");  
	String contextPath = request.getContextPath();

	String strModuleName = "COM";
	//get curuser info  
	HashMap CurUserInfo = (HashMap)session.getAttribute("userinfo");

	if(CurUserInfo == null)
	  CurUserInfo = new HashMap();
	String strCurOrgName = (String)CurUserInfo.get("orgname");
	Integer nCurOrgId = (Integer)CurUserInfo.get("orgid");
	if(nCurOrgId == null)
	  nCurOrgId = new Integer(-1234567);
	Integer curGrade = (Integer)CurUserInfo.get("grade");
	if(curGrade == null)
	  curGrade = new Integer(-1234567);
	
	HashMap centerOrgInfo = (HashMap)session.getAttribute("centerorginfo");
	if(centerOrgInfo == null)
	  centerOrgInfo = new HashMap();
	Integer nCenterOrgId = (Integer)centerOrgInfo.get("orgid");
	boolean bIsCenterOrg = false;
	if(nCurOrgId.equals(nCenterOrgId))
	{
	  bIsCenterOrg = true;
	}

%>

<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/FrmDefault.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>
<html>
<head>
<title>DTPeriodManager</title>
<PageFlow:CheckPageFlow pageName="p_dtperiod" />
<%@ include file="/inc/InitEdit.inc"%>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet"
	href="<%=contextPath %>/css/<%= strLanguageCode %>/main.css"
	type="text/css">
<script language="JavaScript" src="<%=contextPath %>/js/FuncLib.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/Calendar.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/ScriptLib.js"></script>
<%@ include file="/inc/SummaryDivision.inc" %>
<script language="JavaScript">
function page_summary(actionvalue,orderbyname)
{
  var editform = summaryPrepare(frm,actionvalue,orderbyname);
  editform.action = "DTPeriodManager.jsp?<%= OvalTools.randomURL() %>";
  editform.target = "_self";
  isRunning = true;
  
  	editform.submit();  
}

function page_openChecked(){
  frm.actionname.value = "editselectedids";
  setCheckBoxValue('PurchaseDataCollect','hiddenpurchasedatacollect');
  setCheckBoxValue('InvDataCollect','hiddeninvdatacollect');
  setCheckBoxValue('SalesDataCollect','hiddensalesdatacollec');
  frm.target = "_self";
  
 var ispassed =checkchannel();

  if(ispassed){
   frm.submit();  
  }
}

function checkchannel(){
	
    var ispassed=true;
    var checkedAbox=false;
	var SalesDataCheckBox = document.getElementById('SalesDataCollect');
	var InvDataCheckBox = document.getElementById('InvDataCollect');
	var PurchaseDataCheckBox = document.getElementById('PurchaseDataCollect');
	var checkboxarray = document.getElementsByName('checkedids');
	
	for (var i=0 ;i<checkboxarray.length;i++){
		if(checkboxarray[i].checked ){checkedAbox= true;};
	}
	
	if(!checkedAbox){
		alert('<%=message.getMessageDesc("PLEASE_SELECT") %>');
		ispassed= false;
	}
	if(SalesDataCheckBox.checked){
		if(frm.salesdataperiodgroup.value== -1 )
		{alert('<%=message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_SalesDataCollect",false)) %>');
		ispassed= false;}
	}
	if(InvDataCheckBox.checked){
		if(frm.invdataperiodgroup.value== -1 )
		{alert('<%=message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_InvDataCollect",false)) %>');
		ispassed= false;}
	}
	if(PurchaseDataCheckBox.checked){
		if(frm.purchasedataperiodgroup.value== -1 )
		{alert('<%=message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_PurchaseDataCollect",false)) %>');
		ispassed= false;}
	}
	
	return ispassed;
} 

function setCheckBoxValue(checkboxid,hiddenid){

var checkbox = document.getElementById(checkboxid);
var hidden = document.getElementById(hiddenid);



	if(checkbox != null && checkbox.checked == true){
		hidden.value ="Y";
		if(checkbox.id == 'SalesDataCollect'){
			frm.salesdataperiodgroup.disabled= false;
			document.getElementById('SalesData').className ='need';
		}
		if(checkbox.id == 'InvDataCollect'){
			frm.invdataperiodgroup.disabled= false;
			document.getElementById('InvData').className ='need';
		}
		if(checkbox.id == 'PurchaseDataCollect'){
			frm.purchasedataperiodgroup.disabled= false;
			document.getElementById('PurchaseData').className ='need';
		}
	}else{
		hidden.value ="N";
		if(checkbox.id == 'SalesDataCollect'){
			frm.salesdataperiodgroup.selectedIndex= 0;
			frm.salesdataperiodgroup.disabled= true;
			document.getElementById('SalesData').className ='td_center';
			
		}
		if(checkbox.id == 'InvDataCollect'){
			frm.invdataperiodgroup.selectedIndex = 0;
			frm.invdataperiodgroup.disabled= true;
			document.getElementById('InvData').className ='td_center';
			
		}
		if(checkbox.id == 'PurchaseDataCollect'){
			frm.purchasedataperiodgroup.selectedIndex = 0;
			frm.purchasedataperiodgroup.disabled= true;
			document.getElementById('PurchaseData').className ='td_center';
			
		}
	}		 

}

function page_checkall(){
	var allcheck = frm.checkall;
	var allorg = document.getElementsByName("checkedids");
	for(var i = 0 ; i < allorg.length;i++){
		allorg[i].checked = allcheck.checked;
	}
}

function page_uncheckall(element){
	if(!element.checked)frm.checkall.checked = false;
}
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- pageLocation start -->
<%@ include file="/inc/PageLocation.inc" %>
<!-- pageLocation end  -->
<table width="100%" cellspacing="0" cellpadding="0">
	<tr>
		<td class="summary_top"></td>
	</tr>
</table>
<table width="100%" cellspacing="0" cellpadding="0">
	<form name="frm" method="post" action="<%=contextPath %>/Dispatcher">
		<!-- paraments transmission to page start-->
		<input type="hidden" name="pagename" value="p_dtperiod"> 
		<input type="hidden" name="actionname">
		<!-- paraments transmission to page end-->
		<tr>
			<td>
			<!-- location framework table -->
			<table width="100%" border="0" cellspacing="0">
			 	<tr>
	          		<td class="summary_top" ></td>
	        	</tr>
				<!-- serach bar start -->
				<tr>
	          		<td class="summary_top" >
		          		<table>
		          			<%@ include file="/inc/SummarySearch.inc" %>
		          		</table>
	          		</td>
	        	</tr>
				
				<!-- serach bar end -->
				<!-- location framework of summary start -->
				<tr>
					<td>
	      				<table border="1" cellspacing="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellpadding="0" width="100%">
							<!-- table head strat -->
							<tr class="deepblue-left">
								<td width="5%" class="title_center" ><custom:checkbox property="checkall" styleClass="checkbox" onclick="page_checkall()"/></td>
								<td width="55%" class="title_center"><%= label.getLabelName("L_CompanyName") %></td>
								<td width="10%" class="title_center"><%= label.getLabelName("L_Org") + label.getLabelName("L_Code") %></td>
								<td width="10%" class="title_center"><%= label.getLabelName("L_SalesDataCollect") %></td>
								<td width="10%" class="title_center"><%= label.getLabelName("L_InvDataCollect") %></td>		
								<td width="10%" class="title_center"><%= label.getLabelName("L_PurchaseDataCollect") %></td>
							</tr>
							<!-- table head end -->
							<!-- summary start -->
							<logic:present name="totalsummary" scope="page">
								<logic:iterate id="orgPeriod" name="totalsummary"  scope="page"> 
									<tr>
										<td class="td_center"><custom:checkbox name="orgPeriod" property="orgid" changedName="checkedids" styleClass="checkbox" command="notnull" onclick="page_uncheckall(this)"/></td>
										<td><custom:write property="orgname" name="orgPeriod" nbsp="true"/></td>
										<td><custom:write property="orgcode" name="orgPeriod" nbsp="true"/></td>
										<td><custom:write property="periodname1" name="orgPeriod" nbsp="true"/></td>
										<td><custom:write property="periodname2" name="orgPeriod" nbsp="true"/></td>
										<td><custom:write property="periodname" name="orgPeriod" nbsp="true"/></td>
									</tr>
								</logic:iterate>
							</logic:present>
							<%@ include file="/inc/SummaryAction.inc" %>
							<!-- summary end -->
						</table>
					</td>
				</tr>
				<!-- Period type column start -->
				<tr>
					<td>
						<table border="1" cellspacing="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellpadding="0" width="100%">
							<tr >
								<td width="15%" id="SalesData" class="td_center">
									<%=label.getLabelName("L_SalesDataCollect")+label.getLabelName("L_Colon")%>
								</td>
								<td  class="td_left">
									<input id="SalesDataCollect" class="checkbox" type="checkbox" onchange="javascript:setCheckBoxValue('SalesDataCollect','hiddensalesdatacollec');"><%=label.getLabelName("L_SalesDataCollect")%>&nbsp;&nbsp;</input>
									<input id = "hiddensalesdatacollec" type="hidden" name="needsalesdata"/>
									<custom:select optionInnerTextKey="periodname" optionsName="allperiods" property="salesdataperiodgroup" optionValueKey="datacleanperiodid" defaultValue="--------" defaultValueCost="" command="notnull" label="L_SalesDataPeriodGroup" disabled="true"/>
                       			</td>
							</tr>
							<tr>
								<td width="15%" id="InvData" class="td_center">
									<%=label.getLabelName("L_InvDataCollect")+label.getLabelName("L_Colon")%>
								</td>
								<td  class="td_left">
									<input id="InvDataCollect" class="checkbox" type="checkbox" onchange="javascript:setCheckBoxValue('InvDataCollect','hiddeninvdatacollect');"><%=label.getLabelName("L_InvDataCollect")%>&nbsp;&nbsp;</input>
									<input id = "hiddeninvdatacollect" type="hidden" name="needinvdata"/>
									<custom:select optionInnerTextKey="periodname" optionsName="allperiods" property="invdataperiodgroup" optionValueKey="datacleanperiodid" defaultValue="--------" defaultValueCost="" command="notnull" label="L_InvDataPeriodGroup" disabled="true"/>
                        		</td>
							</tr>
							<tr >
								<td width="15%" id ="PurchaseData" class="td_center">   
									<%=label.getLabelName("L_PurchaseDataPeriodGroup")+label.getLabelName("L_Colon")%>
								</td>
								<td  class="td_left">
									<input id="PurchaseDataCollect" class="checkbox" type="checkbox" onchange="javascript:setCheckBoxValue('PurchaseDataCollect','hiddenpurchasedatacollect');"><%=label.getLabelName("L_PurchaseDataPeriodGroup")%>&nbsp;&nbsp;</input>
									<input id = "hiddenpurchasedatacollect" type="hidden" name="needpurchasedata"/>
									<custom:select optionInnerTextKey="periodname" optionsName="allperiods" property="purchasedataperiodgroup" optionValueKey="datacleanperiodid" defaultValue="--------" defaultValueCost="" command="notnull" label="L_PurchaseDataPeriodGroup" disabled="true"/>
                        		</td>
							</tr>
						</table>
					</td>
				</tr>
			
				<!-- location framework of summary end -->
				<tr>
					<!-- button column start -->
					<td class="td_center">
						 <a onclick="javascript:page_openChecked();"><custom:button type="1" label="L_Complete" imgsrc="edit.gif" border="0" style="width:60"/></a>
				     </td>
					<!-- button column end -->
				</tr>
			</table>
			</td>
		</tr>
	</form>
</table>
</body>
</html>



